package com.acwing.partition20;

import java.io.*;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author `RKC`
 * @date 2022/1/10 19:24
 */
public class AC1987粉刷栅栏 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int k = Integer.parseInt(reader.readLine());
        Map<Integer, Integer> map = new TreeMap<>();
        int x = 0;
        while (k-- > 0) {
            String[] s = reader.readLine().split("\\s+");
            int step = Integer.parseInt(s[0]);
            //-2->1,1->-1表示区间[-2, 1)之间被覆盖了一次
            if ("L".equals(s[1])) {
                map.put(x - step, map.getOrDefault(x - step, 0) + 1);
                map.put(x, map.getOrDefault(x, 0) - 1);
                x -= step;
            } else {
                map.put(x, map.getOrDefault(x, 0) + 1);
                map.put(x + step, map.getOrDefault(x + step, 0) - 1);
                x += step;
            }
        }
        //差分
        int answer = 0, sum = 0, last = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if (sum >= 2) answer += entry.getKey() - last;
            sum += entry.getValue();
            last = entry.getKey();
        }
        writer.write(answer + "\n");
        writer.flush();
    }
}
